Why is my debounce function in JavaScript executing calls that should be ignored